#include "Camera.h"
#include "Screen.h"
#include "Volume.h"
#include "FileManager.h"
#include "RayCasting.h"
#include <stdio.h>

int main(int argc, char ** argv)
{

        volume_t volume;
	Screen_t screen;
	Camera_t camera;


	/* Init Volume */
        float pos[3] = {0.0, 0.0, 0.0};
        readHDF5(argv[1], "value", &volume);
        setPositionVolume(&volume, pos);

        int i = 0;
        float max = volume.memory[0];
        float min = volume.memory[0];
	float med = 0.0;
        for(i=1;i<volume.dim[0]*volume.dim[1]*volume.dim[2];i++)
        {
                if (volume.memory[i] > max)
                        max = volume.memory[i];
                if (volume.memory[i] < min)
                        min = volume.memory[i];
		med += volume.memory[i];
        }
        fprintf(stdout, "Max=%f, Min=%f Media=%f\n",max,min,med/(float)(volume.dim[0]*volume.dim[1]*volume.dim[2]));
        float x0 = volume.position[0];
        float x1 = volume.position[0] + volume.dim[0];
        float y0 = volume.position[1];
        float y1 = volume.position[1] + volume.dim[1];
        float z0 = volume.position[2];
        float z1 = volume.position[2] + volume.dim[2];
        fprintf(stdout,"Volumen (%f,%f,%f) (%f,%f,%f)\n",x0,y0,z0,x1,y1,z1);

        fprintf(stdout, "Volumen leido\n");

	/* Init Screen */
	Create_Screen(&screen, 800,800, 50.0, 35.0, 35.0);
	/* Init Camera */
	Camera_Init(&camera);	
	float mov[3] = {350.0,200.0, 1580.0}; 
	Move(&camera,(float*)mov);

	rayCasting(volume, camera, screen);


	Destroy_Screen(screen);
	Camera_Destroy(camera);
	destroyVolume(volume);

	return 0;
}
